package naito_rescue.agent;

import java.util.*;
import java.io.*;
import rescuecore2.worldmodel.*;
import rescuecore2.messages.Command;
import rescuecore2.misc.Pair;
import rescuecore2.misc.geometry.*;
import rescuecore2.log.Logger;
import rescuecore2.standard.entities.*;
import rescuecore2.standard.messages.*;

import naito_rescue.*;
import naito_rescue.agent.*;
import naito_rescue.object.*;
import naito_rescue.router.*;
import naito_rescue.task.*;
import naito_rescue.task.job.*;
import naito_rescue.util.sort.*;
import naito_rescue.util.fb.*;
import naito_rescue.message.*;
import naito_rescue.message.manager.*;
import static naito_rescue.debug.DebugUtil.*;

// テスト用FBエージェント
public class SimpleTestFireBrigade extends NAITOHumanoidAgent<FireBrigade>
{
	int entityid = 33425;
    protected void postConnect() {
        super.postConnect();
        model.indexClass(StandardEntityURN.BUILDING, StandardEntityURN.REFUGE);

		//search.searchAllPaths(new EntityID(entityid));
	}

	public String toString(){
		return "NAITOFireBrigade." + me().getID() + "";
	}
	
	public void think(int time, ChangeSet changed, Collection<Command> heard){
		//Youzinbou, master_gradthesis_test_environment, Kobe2
		//単一の建物を探索する。このとき、A*法の他に、全経路の候補を探索させる。
		super.think(time, changed, heard);
		
		String context = "TestFB#think";
		if (time < config.getIntValue(kernel.KernelConstants.IGNORE_AGENT_COMMANDS_KEY)){
			return;
		}else if(time == config.getIntValue(kernel.KernelConstants.IGNORE_AGENT_COMMANDS_KEY)){
			//logger.info("Number of crowling-buildings = " + crowlingBuildings.size(), context);
		}
		
		String contextFromTo = "[" + getLocation().getID() + " -> " + entityid + " ]";
		//logger.info("\n");
		
		StandardEntity entity = model.getEntity(new EntityID(entityid));
		//List<List<EntityID>> allPaths = search.searchAllPaths(entity.getID());
		//List<EntityID> astarPath = search.astarSearch(entity);
		//List<EntityID> astarPath2 = search.astarSearch2(entity);
		List<EntityID> aastarPath = search.adaptiveAStarSearch(entity);
		List<EntityID> backPath = search.backwardAStarSearch(entity);
		//List<EntityID> backPath2 = search.backwardAStarSearch2(entity);
		/*
		if(allPaths != null){
			//logger.trace("allPaths is not null. size() = " + allPaths.size(), context);
			for(List<EntityID> path : allPaths){
				if(path != null){
					//logger.debug(contextFromTo + " Path Length = " + search.computePathLength(path), context);
				}
			}
		}else{
			//logger.info("All-Path-find is failed.", context);
		}
		*/
		/*
		if(astarPath != null){
			//logger.debug(contextFromTo + " A* Path Length = " + search.computePathLength(astarPath), context);
		}
		if(astarPath2 != null){
			//logger.debug(contextFromTo + " A* (maybe fixed) Path length = " + search.computePathLength(astarPath2), context);
		}
		*/
		
		/*
		if(aastarPath != null){
			//logger.info("move to " + entity.getID(), context);
			move(aastarPath);
		}
		*/
	}
	
	protected EnumSet<StandardEntityURN> getRequestedEntityURNsEnum(){
		return EnumSet.of(StandardEntityURN.FIRE_BRIGADE);
	}
}
